package cdu.sl.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 首页控制器
 */
@Controller
@Slf4j
public class IndexController {

    /**
     * 处理根路径访问，重定向到登录页面
     * @return
     */
    @GetMapping("/")
    public String index() {
        log.info("访问根路径，重定向到登录页面");
        return "redirect:/page/login";
    }
    
    /**
     * 处理/index路径访问，跳转到首页
     * @return
     */
    @GetMapping("/index")
    public String indexPage() {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null && auth.isAuthenticated()) {
            log.info("用户 {} 访问首页，拥有权限: {}", 
                    auth.getName(), auth.getAuthorities());
        } else {
            log.warn("未认证用户访问首页");
        }
        return "index";
    }


} 